package com.feiyu.blog.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feiyu.blog.entity.Picture;
import com.feiyu.blog.service.PictureService;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tang ming
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/picture")
@AllArgsConstructor
public class PictureController {

    private PictureService pictureService;

    @GetMapping("/detail/{id}")
    public R<Picture> detail(@PathVariable int id){
        return R.data(pictureService.getById(id));
    }

    @GetMapping("/list")
    public R<IPage<Picture>> list(Page<Picture> page){
        return R.data(pictureService.page(page));
    }

    @PostMapping("/save")
    public R save(@RequestBody Picture picture){
        return R.status(pictureService.save(picture));
    }

    @PostMapping("/update")
    public R update(@RequestBody Picture picture){
        return R.status(pictureService.updateById(picture));
    }

    @PostMapping("/delete/{id}")
    public R delete(@PathVariable int id){
        return R.status(pictureService.removeById(id));
    }
}

